% File for parsing data.m file
close all
clear all
fprintf('Choose file:\n');
fprintf('[1] : data.txt\n');
fprintf('[2] : data_backup.txt\n');
fprintf('[3] : Other file\n');
fprintf('Enter number: ');
number = sscanf(input('','s'),'%s');

if(isequal(number,'1') || isequal(number,[]))
    fname = 'data.txt';
elseif(number=='2')
    fname = 'data_backup.txt';
elseif(number=='3')
    fprintf('Enter file name: ');
    fname = sscanf(input('','s'),'%s');
else
    disp('Illegal number');
    break;
end

file = fopen(fname);

number = fscanf(file,'%i\n', 1);

i=0;
while(1)
    i = i+1;
    coord = fscanf(file,'%f %f\n', 2);
    if isequal(size(coord),[2 1]);
        k(:,i) = coord;
    else
        break
    end
end

fclose(file);

figure;
scatter(k(1,:),k(2,:),'filled');
axis equal
points = size(k,2);
name = sprintf('Number of crickets: %i, Number of points: %i', number, points);
title(name);
shg

%Data dichtheid plot
%Bron: http://www.mathworks.com/matlabcentral/fileexchange/31726-data-density-plot/content/DataDensity/DataDensityPlot.m
DataDensityPlot(k(1,:),k(2,:), 128);